package qianchuan

import (
	"cid-media-api/api/common"
	"cid-media-api/api/ocean"
	"cid-media-api/models"
	"context"
	. "github.com/oceanengine/ad_open_sdk_go/models"
	"net/http"
)

func GetAdvertiserReport(
	account models.MediaAccount,
	startDate string,
	endDate string,
	page int32,
	pSize int32,
	timeGranularity QianchuanReportAdvertiserGetV10TimeGranularity,
) *QianchuanReportAdvertiserGetV10ResponseData {
	ctx := context.Background()

	fields := []string{
		"stat_cost",
		"show_cnt",
		"cpm_platform",
		"click_cnt",
		"cpc_platform",
		"ctr",
		"convert_cnt",
		"convert_cost",
		"create_order_amount",
		"create_order_roi",
		"total_play",
		"play_duration_3s",
		"prepay_and_pay_order_roi",
		"pay_order_amount",
	}

	filtering := QianchuanReportAdvertiserGetV10Filtering{
		MarketingGoal: ALL_QianchuanReportAdvertiserGetV10FilteringMarketingGoal,
	}

	res, _ := ocean.Call(func() (any, *http.Response, error) {
		return ocean.Api.QianchuanReportAdvertiserGetV10Api().Get(ctx).
			AccessToken(account.AccessToken).
			AdvertiserId(account.AdvertiserId).
			StartDate(startDate).
			EndDate(endDate).
			Fields(fields).
			TimeGranularity(timeGranularity).
			Filtering(filtering).
			Page(page).
			PageSize(pSize).
			Execute()

	}, common.GetAdvertiserReportQC())

	if res == nil {
		return nil
	}

	resData := res.(*QianchuanReportAdvertiserGetV10Response).Data

	return resData
}
